home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Commodities / PointHack / PointHack.c < prev    next >
C/C++ Source or Header  |  1996-09-26  |  7KB  |  239 lines

  1. /* PointHack.c
  2.  
  3.  * Changes mouse colour on single and double mouse press
  4.  * runs as a commodity
  5.  * requires V38 of commodities.library
  6.  *
  7.  * Freely distributable
  8.  *
  9.  * mpaddock@cix.compulink.co.uk
  10.  */
  11.  
  12. #include <intuition/intuitionbase.h>
  13. #include <clib/intuition_protos.h>
  14. struct IntuitionBase *IntuitionBase;
  15. #include <pragmas/intuition_pragmas.h>
  16.  
  17. #include <clib/exec_protos.h>
  18. extern struct Library *SysBase;
  19. #include <pragmas/exec_pragmas.h>
  20.  
  21. #include <clib/graphics_protos.h>
  22. struct Library *GfxBase;
  23. #include <pragmas/graphics_pragmas.h>
  24.  
  25. #include <clib/commodities_protos.h>
  26. struct Library *CxBase;
  27. #include <pragmas/commodities_pragmas.h>
  28.  
  29. #include <clib/icon_protos.h>
  30. struct Library *IconBase;
  31. #include <pragmas/icon_pragmas.h>
  32.  
  33. #include <devices/timer.h>
  34.  
  35. #include <clib/timer_protos.h>
  36. struct Library *TimerBase=NULL;
  37. #include <pragmas/timer_pragmas.h>
  38.  
  39. #include <clib/alib_protos.h>
  40.  
  41. #include <dos/dos.h>
  42.  
  43. void
  44. ColorPointer(BOOL doubleclick);
  45.  
  46. void
  47. UnColorPointer(void);
  48.  
  49. UBYTE *vers = "$VER: PointHack 1.0 (16.5.93)";
  50.  
  51. UBYTE dr[3],dg[3],db[3];
  52. UBYTE ddr[3],ddg[3],ddb[3];
  53.  
  54. void
  55. main(int argc, char **argv) {
  56.     struct NewBroker newbroker = {
  57.         NB_VERSION,
  58.         "PointHack 1.0",
  59.         "Pointer colour changer",
  60.         "Change pointer colour on mouse press",
  61.         NBU_UNIQUE|NBU_NOTIFY,
  62.         0,
  63.         0,
  64.         0,
  65.         0
  66.     };
  67.     struct timeval  time1, time2;
  68.     struct timerequest tr;
  69.     UBYTE **ttypes;
  70.     struct MsgPort *broker_mp;
  71.     CxMsg  *msg;
  72.     CxObj *broker,*down,*up,*upf,*downf;
  73.     ULONG downs,ups;
  74.     ULONG signals = SIGBREAKF_CTRL_C;
  75.     ULONG sigrcvd;
  76.     struct Task *task;
  77.     BOOL flag = TRUE;
  78.     if (IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37)) {
  79.         if (GfxBase = OpenLibrary("graphics.library",37)) {
  80.             if (IconBase = OpenLibrary("icon.library",37)) {
  81.                 if (CxBase = OpenLibrary("commodities.library",38)) {
  82.                     if (broker_mp = CreateMsgPort()) {
  83.                         signals |= (1L << broker_mp->mp_SigBit);
  84.                         ttypes = ArgArrayInit(argc,argv);
  85.                         dr[0] = (UBYTE)ArgInt(ttypes,"R1",0);
  86.                         dr[1] = (UBYTE)ArgInt(ttypes,"R2",0);
  87.                         dr[2] = (UBYTE)ArgInt(ttypes,"R3",0);
  88.                         dg[0] = (UBYTE)ArgInt(ttypes,"G1",0);
  89.                         dg[1] = (UBYTE)ArgInt(ttypes,"G2",0);
  90.                         dg[2] = (UBYTE)ArgInt(ttypes,"G3",0);
  91.                         db[0] = (UBYTE)ArgInt(ttypes,"B1",0);
  92.                         db[1] = (UBYTE)ArgInt(ttypes,"B2",0);
  93.                         db[2] = (UBYTE)ArgInt(ttypes,"B3",0);
  94.                         ddr[0] = (UBYTE)ArgInt(ttypes,"DR1",15);
  95.                         ddr[1] = (UBYTE)ArgInt(ttypes,"DR2",15);
  96.                         ddr[2] = (UBYTE)ArgInt(ttypes,"DR3",15);
  97.                         ddg[0] = (UBYTE)ArgInt(ttypes,"DG1",15);
  98.                         ddg[1] = (UBYTE)ArgInt(ttypes,"DG2",15);
  99.                         ddg[2] = (UBYTE)ArgInt(ttypes,"DG3",15);
  100.                         ddb[0] = (UBYTE)ArgInt(ttypes,"DB1",15);
  101.                         ddb[1] = (UBYTE)ArgInt(ttypes,"DB2",15);
  102.                         ddb[2] = (UBYTE)ArgInt(ttypes,"DB3",15);
  103.                         newbroker.nb_Port = broker_mp;
  104.                         newbroker.nb_Pri = (BYTE)ArgInt(ttypes,"CX_PRIORITY",0);
  105.                         task = FindTask(NULL);
  106.                         if (broker = CxBroker(&newbroker,NULL)) {
  107.                             if (upf = CxFilter("rawmouse -caps -alt -lcommand -rcommand -control leftbutton upstroke mouse_leftpress")) {
  108.                                 AttachCxObj(broker, upf);
  109.                                 if (downf = CxFilter("rawmouse -caps -alt -lcommand -rcommand -control leftbutton mouse_leftpress")) {
  110.                                     AttachCxObj(broker, downf);
  111.                                     if ((downs = (ULONG)AllocSignal(-1L)) != -1) {
  112.                                         signals |= (1L << downs);
  113.                                         if (down = CxSignal(task,downs)) {
  114.                                             AttachCxObj(downf,down);
  115.                                             if ((ups = (ULONG)AllocSignal(-1L)) != -1) {
  116.                                                 signals |= (1L << ups);
  117.                                                 if (up = CxSignal(task,ups)) {
  118.                                                     AttachCxObj(upf,up);
  119.                                                     if (!OpenDevice(TIMERNAME,UNIT_MICROHZ,(struct IORequest *) &tr, 0L)) {
  120.                                                       TimerBase = (struct Library *)tr.tr_node.io_Device;
  121.                                                         ActivateCxObj(broker,TRUE);
  122.                                                         while (flag) {
  123.                                                             sigrcvd = Wait(signals);
  124.                                                                 if (sigrcvd & (1L << broker_mp->mp_SigBit)) {
  125.                                                                 while (msg = (CxMsg *)GetMsg(broker_mp)) {
  126.                                                                     switch (CxMsgType(msg)) {
  127.                                                                     case CXM_COMMAND:
  128.                                                                         switch (CxMsgID(msg)) {
  129.                                                                         case CXCMD_DISABLE:
  130.                                                                             ActivateCxObj(broker,FALSE);
  131.                                                                             UnColorPointer();
  132.                                                                             break;
  133.                                                                         case CXCMD_ENABLE:
  134.                                                                             ActivateCxObj(broker,TRUE);
  135.                                                                             break;
  136.                                                                         case CXCMD_KILL:
  137.                                                                         case CXCMD_UNIQUE:
  138.                                                                             flag = FALSE;
  139.                                                                             break;
  140.                                                                         default:
  141.                                                                             break;
  142.                                                                         }
  143.                                                                     default:
  144.                                                                         break;
  145.                                                                     }
  146.                                                                     ReplyMsg((struct Message *)msg);
  147.                                                                 }
  148.                                                             }
  149.                                                             if (sigrcvd & SIGBREAKF_CTRL_C) {
  150.                                                                 flag = FALSE;
  151.                                                             }
  152.                                                             if (sigrcvd & (1L << downs)) {
  153.                                                                 if (!(sigrcvd & (1L << ups))) {
  154.                                                                     GetSysTime(&time2);
  155.                                                                     ColorPointer(DoubleClick(time1.tv_secs,time1.tv_micro,
  156.                                                                                                                      time2.tv_secs,time2.tv_micro));
  157.                                                                     time1 = time2;
  158.                                                                 }
  159.                                                             }
  160.                                                             if (sigrcvd & (1L << ups)) {
  161.                                                                 UnColorPointer();
  162.                                                             }
  163.                                                         }
  164.                                                         UnColorPointer();
  165.                                                         CloseDevice((struct IORequest *) &tr);
  166.                                                     }
  167.                                                 }
  168.                                                 FreeSignal(ups);
  169.                                             }
  170.                                         }
  171.                                         FreeSignal(downs);
  172.                                     }
  173.                                 }
  174.                             }
  175.                             while (msg = (CxMsg *)GetMsg(broker_mp)) {
  176.                                 ReplyMsg((struct Message *)msg);
  177.                             }
  178.                             DeleteCxObjAll(broker);
  179.                         }
  180.                         DeletePort(broker_mp);
  181.                     }
  182.                     CloseLibrary(CxBase);
  183.                 }
  184.                 CloseLibrary(IconBase);
  185.             }
  186.             CloseLibrary(GfxBase);
  187.         }
  188.         CloseLibrary((struct Library *)IntuitionBase);
  189.     }
  190. }
  191.  
  192. UBYTE r[3],g[3],b[3];            /* Saved rgb colors */
  193. struct Screen *screen=NULL;
  194.  
  195. /* Colour the pointer
  196.  */
  197. void
  198. ColorPointer(BOOL doubleclick) {
  199.     UWORD i;                    /* Loop counter    */
  200.     UWORD color;            /* Colour            */
  201.     /* Store 3 colours    */
  202.     Forbid();
  203.     screen = IntuitionBase->ActiveScreen;
  204.     for (i=0; i<3; i++) {
  205.         color = GetRGB4(screen->ViewPort.ColorMap,i+17);
  206.         r[i]=(color&0x0f00)>>8;
  207.         g[i]=(color&0x00f0)>>4;
  208.         b[i]=(color&0x000f);
  209.     }
  210.     /* Update 3 colours    */
  211.     if (doubleclick) {
  212.         for (i=0; i<3; i++) {
  213.             SetRGB4(&(screen->ViewPort),17+i,ddr[i],ddg[i],ddb[i]);
  214.         }
  215.     }
  216.     else {
  217.         for (i=0; i<3; i++) {
  218.             SetRGB4(&(screen->ViewPort),17+i,dr[i],dg[i],db[i]);
  219.         }
  220.     }
  221.     Permit();
  222. }
  223.  
  224. /* UnColour the pointer
  225.  */
  226. void
  227. UnColorPointer(void) {
  228.     UWORD i;                    /* Loop counter    */
  229.     /* redo 3 colours    */
  230.     Forbid();
  231.     if (screen) {
  232.         for (i=0; i<4; i++) {
  233.             SetRGB4(&(screen->ViewPort),17+i,r[i],g[i],b[i]);
  234.         }
  235.     }
  236.     screen = NULL;
  237.     Permit();
  238. }
  239.